package ua.lviv.franko.solvers.stressanalysis.twoDimention.fem;

import java.util.ArrayList;
import java.util.List;

import ua.lviv.franko.integration.IFEMFunction2D;
import ua.lviv.franko.triangulation.SaveStructures.Node;

public class BiquadraticrIsoparamerticQuadrilateral extends AbstractIsoparametricQuadrilateral {

	public BiquadraticrIsoparamerticQuadrilateral(double k1, double k2, double k3, IFEMFunction2D f1Function, IFEMFunction2D f2Function, List<Node> nodes) {
		super(k1, k2, k3, f1Function, f2Function);

		this.nodes = nodes;
		this.pos = new ArrayList<Integer>();
		for (Node node : nodes) {
			pos.add(node.Number);
		}

		// add base functions

		// N1
		IFEMFunction2D Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x) * (1.0 - y) * (1.0 + x + y) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (-(1.0 - y) * (1.0 + x + y) + (1.0 - x) * (1.0 - y)) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (-(1.0 - x) * (1.0 + x + y) + (1.0 - x) * (1.0 - y)) / 4.0;
			}

			@Override
			public double getXi() {
				return -1.0;
			}

			@Override
			public double getYi() {
				return -1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N2
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x * x) * (1.0 - y) / 2.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (-x) * (1.0 - y);
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return -(1.0 - x * x) / 2.0;
			}

			@Override
			public double getXi() {
				return 0.0;
			}

			@Override
			public double getYi() {
				return -1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N3
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 + x) * (1.0 - y) * (x - y - 1.0) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return ((1.0 - y) * (x - y - 1.0) + (1.0 + x) * (1.0 - y)) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (-(1.0 + x) * (x - y - 1.0) - (1.0 + x) * (1.0 - y)) / 4.0;
			}

			@Override
			public double getXi() {
				return 1.0;
			}

			@Override
			public double getYi() {
				return -1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N4
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 + x) * (1.0 - y * y) / 2.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (1.0 - y * y) / 2.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (1.0 + x) * (-y);
			}

			@Override
			public double getXi() {
				return 1.0;
			}

			@Override
			public double getYi() {
				return 0.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N5
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 + x) * (1.0 + y) * (x + y - 1.0) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return ((1.0 + y) * (x + y - 1.0) + (1.0 + x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return ((1.0 + x) * (x + y - 1.0) + (1.0 + x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double getXi() {
				return 1.0;
			}

			@Override
			public double getYi() {
				return 1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N6
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x * x) * (1.0 + y) / 2.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (-x) * (1.0 + y);
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (1.0 - x * x) / 2.0;
			}

			@Override
			public double getXi() {
				return 0.0;
			}

			@Override
			public double getYi() {
				return 1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N7
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x) * (1.0 + y) * (y - x - 1.0) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (-(1.0 + y) * (y - x - 1.0) - (1.0 - x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return ((1.0 - x) * (y - x - 1.0) + (1.0 - x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double getXi() {
				return -1.0;
			}

			@Override
			public double getYi() {
				return 1.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N8
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x) * (1.0 + y) * (y - x - 1.0) / 4.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return (-(1.0 + y) * (y - x - 1.0) - (1.0 - x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return ((1.0 - x) * (y - x - 1.0) + (1.0 - x) * (1.0 + y)) / 4.0;
			}

			@Override
			public double getXi() {
				return -1.0;
			}

			@Override
			public double getYi() {
				return 0.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

		// N9
		Ni = new IFEMFunction2D() {

			@Override
			public double calculate(double x, double y) {
				return (1.0 - x) * (1.0 - y * y) / 2.0;
			}

			@Override
			public double calculateDerivatyX(double x, double y) {
				return -(1.0 - y * y) / 2.0;
			}

			@Override
			public double calculateDerivatyY(double x, double y) {
				return (1.0 - x) * (-y);
			}

			@Override
			public double getXi() {
				return -1.0;
			}

			@Override
			public double getYi() {
				return 0.0;
			}

			@Override
			public Node getNode() {
				// TODO Auto-generated method stub
				return null;
			}
		};

		baseFunctions.add(Ni);

	}

	@Override
	public double calculateSigma11(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public double calculateSigma12(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public double calculateSigma22(double x, double y, double[] vals) {
		// TODO Auto-generated method stub
		return 0;
	}

}
